<!DOCTYPE html>
<html>
    <head>
        <title>
            Tesdo Admin
        </title>
        <?php
        require_once dirname(dirname(__FILE__)) . '/shared/config/config.php';
        require_once DOCUMENT_ROOT . DIR_SHARED_DAO . 'dao_user.php';
        require_once DOCUMENT_ROOT . DIR_SHARED_DTO . 'dto_user.php';
        require_once DOCUMENT_ROOT . DIR_SHARED_LIBRARIES . 'lib_redirect.php';
        require_once DOCUMENT_ROOT . DIR_ADMIN_INCLUDE . 'head.php';
        ?>
    </head>
    <body>
        <?php
        if (!empty($_POST['btnForgot'])) {
            $dao_user = new dao_user();
            if($dao_user->get_admin_password()){
            ?>
            <script type="text/javascript">
                alert('Password has been sent to admin email address!');
            </script>
            <?php } else {
            ?>
            <script type="text/javascript">
                alert('Failed to send the recover password!');
            </script>
            <?php }
        } else {
//            session_start();
            if (!empty($_POST)) {
                $dao_user = new dao_user();
                $username = $_POST['txtName'];
                $password = $_POST['txtPasword'];
                $result = $dao_user->login($username, $password);
                if (!empty($result)) {
                    session_start();
                    $_SESSION['user'] = 'logined';
                    lib_redirect::Redirect('/admin/index.php');
                } else {
                    $error = 'Login failed!';
                }
            }
        }
        ?>
        <div id="outerMost">
            <br>
            <br>
            <div id="AdminLogin">
                <div id="loginHeading">
                    Admin Login
                </div>
                <?php if (!empty($error)) { ?>
                    <div style="color:red">
                        <?php echo $error; ?>
                    </div>
                <?php }
                ?>
                <form action="login.php" method="POST" id="formLogin">
                    <table style="width: 100%; padding-left: 20px; height: 166px;">
                        <tbody>
                            <tr>
                                <td style="width: 87px; height: 13px;">
                                </td>
                                <td class="style5">
                                </td>
                            </tr>
                            <tr style="margin-bottom: 10px;">
                                <td class="style8" style="padding: 5px; color: #FFFFFF; font-size: 11pt; height: 40px;">
                                    &nbsp;Username:
                                </td>
                                <td class="style9">
                                    <input name="txtName" type="text" id="txtName" class="txtBox" required>
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td class="style8" style="color: #FFFFFF; font-size: 11pt; height: 40px;">
                                    &nbsp; Password:
                                </td>
                                <td class="style7">
                                    <input name="txtPasword" type="password" id="txtPasword" class="txtBox" required>
                                </td>
                            </tr>
                            <tr>
                                <td class="style8">
                                    &nbsp;
                                </td>
                                <td class="style11">
                                    <input type="submit" name="btnSubmit" value="Submit" id="btnSubmit">
                                    <input type="submit" name="btnForgot" value="Forgot Password" id="btnForgot">
                                </td>
                            </tr>
                            <tr align="center">
                                <td class="style1" colspan="2" align="center" valign="middle">
                                    &nbsp;<span id="lblMsg" style="color:White;font-size:11pt;font-weight:normal;"></span>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </form>
            </div>
        </div>
    </body>
</html>
